package com.mentalhealthplatform.studentV3.service;

import com.mentalhealthplatform.appModels.Tweet;
import com.mentalhealthplatform.studentV3.repository.TweetRepositoryV3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class TweetServiceV3 {

    @Autowired
    private TweetRepositoryV3 tweetRepositoryV3;


    public List<Tweet> getAllTweets() {
        return tweetRepositoryV3.findAll();
    }

    public Tweet getTweetById(Long id) {
        Optional<Tweet> tweet = tweetRepositoryV3.findById(id);
        return tweet.orElse(null);
    }

    /*public List<Tweet> searchTweets(String keyword) {
        return tweetElasticsearchRepository.searchByContent(keyword);
    }*/

    public Tweet saveTweet(Tweet tweet) {
        return tweetRepositoryV3.save(tweet); // Save to database
        //return tweetElasticsearchRepository.save(tweet); // Save to Elasticsearch
    }

    public void deleteTweetById(Long id) {
        tweetRepositoryV3.deleteById(id); // Delete from database
        //tweetElasticsearchRepository.deleteById(id); // Delete from Elasticsearch
    }
}